// pages/lrq_lottery_draw/lrq_lottery_draw.js
Component({
  properties: {
    prizeImgItem: {
      type: Array,
      value: []
    }
  },
  data:{
    currPoint: 0,
    currPrize: 0
  },
  created:function(){
    this.tim = null;
    this.tp = 100;
    this.startFlag = true;
    this.ct = 0; //这个可以确定你要中哪个,嘿嘿
  },
  ready:function(){
    let that = this;
    let timer = setInterval(function(){
      let tem = that.data.currPoint? 0:1;
      that.setData({
        currPoint: tem
      }); 
    },500);
  },
  methods:{
    startPrize:function(){
     
      let that = this;
      if (!this.startFlag){
        return;
      }
      this.startFlag = false;
      this.setData({
        currPrize: 0
      });
      
      //奖品数量8个，所以8的倍数依次往后退可以算出你想要那个结果
      //也可以设定真正的随机,也可以设定哪几个中间选一个
      let randomNum = Math.floor(Math.random() * (7 - 0 + 1) + 0);
      let randomArr = [0,1,2,3,5,6,7,8];
      console.log('随机数字是' + randomNum)
      this.tim = setInterval(fn, this.tp);

      function fn() {
        let tem = that.data.currPrize;
        tem = tem + 1;
        that.ct = that.ct + 1;
        if(tem > 7){
          tem = 0;
        }
        that.setData({
          currPrize: tem
        });

        //转盘的转动动画的速度变化,怎么合适怎么设置
        if (that.tp < 200){
          that.tp = that.tp + 5;
        }else{
          that.tp = that.tp + 100;
        }
        clearInterval(that.tim);

        if (that.ct < 16 + randomArr[randomNum]) {
          that.tim = setInterval(fn, that.tp);
        }else{
          console.log("停止");
          clearInterval(that.tim);
          that.tp = 100;
          that.startFlag = true;
          that.ct = 0;
          wx.showModal({
            title: '恭喜您',
            content: "获得了第" + that.data.prizeImgItem[tem].prizeName,
            showCancel: false,//去掉取消按钮
            success: function (res) {
              if (res.confirm) {}
            }
          });
        }
      } 
    }
  }
})